package com.dream.inspect.common.utils;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
/**
 * @Title 扩展BeanUtils.copyProperties支持date类型
 * @Description
 * @author wuxp
 * @date 2018-08-02
 */
public class BeanUtilsEx extends BeanUtils {
    private static final Logger logger = LoggerFactory.getLogger(BeanUtilsEx.class);
 
	static {
		ConvertUtils.register(new DateConvert(), java.util.Date.class);
		ConvertUtils.register(new DateConvert(), String.class);
	}
 
	public static void copyProperties(Object target, Object source) {
		// 支持对日期copy
		try {
			org.apache.commons.beanutils.BeanUtils.copyProperties(target, source);
		} catch (IllegalAccessException | InvocationTargetException e) {
			logger.error("扩展BeanUtils.copyProperties支持date类型:" + e.getMessage());
			e.printStackTrace();
		}
	}
}

